<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cell {
    background: #fff;
  }
  #acts span {
    font-size: 14px;
  }
  .weui-label{
    /*width: 130px;*/
    text-align: left;
  }

  .weui-select {
    height: auto;
    line-height: normal;
  }
  *{
    list-style:none;
  }
  /*body{*/

  /*}*/
  .weui-cell_select {
    padding: 10px 15px;
  }
  .weui-cells__title {
    text-align: left;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  input.time {
    border: none;
    font-size: 16px;
    padding-left: 10px;
  }
</style>
<template>
  <div class="oitem">
    <div class="weui-cells__title">货品明细{{itemNo + 1}}
      <p id="acts" style="float: right;color: #1aad19;" v-if="isLast">
        <span id="addItem" @click="addItem" style="padding-right: 5px;">添加</span>
        <span v-if="itemNo != 0">|</span>
        <span id="delItem" style="padding-left: 5px;" @click="delItem" v-if="itemNo != 0">删除</span>
      </p>
    </div>
    <div class="weui-cell weui-cell_select fir">
      <div class="weui-cell__hd"><label class="weui-label">货品类型</label></div>
      <div class="weui-cell__bd">
<!--        <input type="hidden" :name="'items[' + itemNo + '].type'" :value="type" />-->
        <select class="weui-select" :name="'items[' + itemNo + '].type'" v-model="type">
          <option value="1" >原料</option>
<!--          <option value="2" >产品</option>-->
<!--          <option value="3" >次品</option>-->
        </select>
      </div>
    </div>
    <div class="weui-cell weui-cell_select fir">
      <div class="weui-cell__hd"><label class="weui-label">产品</label></div>
      <div class="weui-cell__bd">
        <input type="hidden" ref="product" :name="'items[' + itemNo + '].product'">
        <select class="weui-select product" ref="prod" v-model="currentProduct" :name="'items[' + itemNo + '].productguid'">
          <option value="" disabled>请选择</option>
          <option selected="" v-if="transferType == 6" v-for="(item, index) in products" :key="item.guid" :value="item.guid">{{item.productname}}</option>
          <option selected="" v-if="transferType == 5" v-for="(item, index) in products3" :key="item.guid" :value="item.guid">{{item.productname}}</option>
        </select>
      </div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label">重量</label></div>
      <div class="weui-cell__bd">
        <input class="weui-input weight inlinput1" type="number" :name="'items[' + itemNo + '].shiftweight'" placeholder="请输入重量" />
        <input class="weui-input inlinput2" readonly value="吨" />
      </div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label">备注</label></div>
      <div class="weui-cell__bd">
        <textarea class="weui-textarea" :name="'items[' + itemNo + '].remark'" placeholder="请输备注内容" rows="2"></textarea>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TransferApplyItem',
  data () {
    return {
      openid: localStorage.openid,
      products: [],
      products3: [],
      currentProduct: '',
      specifications: [],
      type: 1,
      houses: [],
      houseid: '',
      spguid: '',
      showSpec: true
    }
  },
  props: [
    'itemNo',
    'isLast',
    'orgid',
    'roomid',
    'parentType',
    'transferType'
  ],
  computed: {

  },
  mounted() {
    this.getProducts();
    this.getProductinfo();
  },
  watch: {
    'roomid': function(){
      this.getProducts();
      // this.getSpecs();
    },
    'type': function(val){
      // this.getSpecs();
      // this.showSpec = true;
      this.getProducts();
    },
    'orgid': function(){
      this.getProducts();
      // this.getSpecs();
    },
    // 'houseid': function(){
    //   this.getProducts();
    //   this.getSpecs();
    //   let index=this.$refs.fromsh.selectedIndex ;
    //   this.$refs.fromshname.value = this.$refs.fromsh.options[index].text;
    // },
    'currentProduct': function (val) {
      // this.getSpecs();
      let index=this.$refs.prod.selectedIndex ;
      this.$refs.product.value = this.$refs.prod.options[index].text;
    },
    'spguid': function (val) {
      let index=this.$refs.spec.selectedIndex ;
      this.$refs.spname.value = this.$refs.spec.options[index].text;
    }
  },
  methods: {
    addItem: function () {
      this.$emit('doAddItem');
    },
    delItem: function () {
      this.$emit('doDelItem');
    },
    getHouses: function () {
      if (this.roomid == '' || this.type == '' || this.currentProduct == '' || this.orgid == '') return;
      this.axios({
        method: 'get',
        url: '/sales/Whoutform!getPLInfo.action',
        params: {
          orgid: this.orgid,
          strmid: this.roomid,
          picktype: this.type,
          productid: this.currentProduct,
          spec: this.spguid
        }
      }).then((response) => {
        if (response.data.houses != undefined) {
          let data = response.data;
          this.houses = data.houses;
        } else if (response.data.msg == 'outlogin') {
          this.toastText('请重新登录');
        } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          this.toastText("获取库间数据失败");
        }

      })
    },
    getProducts: function () {
      if (this.roomid == '') return;
      this.axios({
        method: 'get',
        url: '/sales/Sellform!findProductinfoBYStr.action',
        params: {guid: this.roomid, type: this.type}
      }).then((response) => {
        if (response.data.status == 'true') {
          this.products = response.data.result;
        } else if (response.data.status == 'false') {
          this.toastText(response.data.result);
        } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          this.toastError("系统错误");
        }
      })
    },
    getProductinfo: function () {
      let that = this;
      this.axios({
        method: 'get',
        responseType: 'json',
        url: '/sales/Sellform!findProductinfo.action'
      }).then(response => {
        if (response.data.status == "true") {
          this.products3 = response.data.result;
        } else {
          this.toastText('获取货品数据失败')
        }
      });
    },
    getSpecs: function() {
      //调整出库
      if (this.transferType == 2) {
        if (this.orgid == '' || this.roomid == '' || this.currentProduct == '' || this.type == 1) {
          return;
        }
        this.axios({
          method: 'get',
          url: '/sales/Whoutform!getSpesByWinfo.action',
          params: {orgid: this.orgid, strmid: this.roomid, productid: this.currentProduct, picktype: this.type}
        }).then((response) => {
          if (response.data.spes != undefined) {
            this.specifications = response.data.spes;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
            this.toastText('获取规格数据失败');
          }

        })
      }
      //调整入库
      if (this.transferType == 3) {
        this.axios({
          method: 'get',
          url: '/produce/Whinapply!getSpeByproduct.action',
          params: {productid: this.currentProduct, type: this.type, stats: '1,4'}
        }).then((response) => {
          if (response.data.msg == 'success') {
            let data = response.data;
            this.specifications = data.specifications;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
            this.toastText("获取规格数据失败");
          }

        })
      }
    },
  }
}
</script>
